package com.binhai.springboot.menu.service;

import com.binhai.springboot.menu.bean.MenuBean;
import com.binhai.springboot.menu.dao.MenuBeanDao;
import com.binhai.springboot.user.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings("ALL")
@Service
public class MenuService {

    @Autowired
    private MenuBeanDao menuDao;

    public List getAllData() {

        return menuDao.getAllData();
    }


        public List getAllTreeData() {
        return menuDao.getAllTreeData ();
    }

    public List selectData(String name) {
        return menuDao.selectData(name);

    }

    public Map saveData(MenuBean bean) {
        Map re = new HashMap ( );
        try {
            menuDao.insertData(bean);
            re.put ("result", "success");
        } catch (Exception e) {
            re.put ("result", "error");
            e.printStackTrace ( );
        }
        return re;
    }



    public Map updateData(MenuBean bean) {
        Map re = new HashMap();
        try {
            //修改数据
            menuDao.updateData(bean);

            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public Map deleteData(MenuBean bean) {
        Map re = new HashMap();
        try {

            menuDao.deleteData(bean);
            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public MenuBean getAllMenu() {
        return menuDao.getAllMenu ();
    }

    public MenuBean getCurrentUserAllMenu(UserBean user) {
        return menuDao.getCurrentUserAllMenu(user);
    }
}
